//
//  SEDepartmentViewModel.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/25.
//

import UIKit

class SEDepartmentViewModel: SEBaseViewModel {
    var departmentList: [SEDepartmentItem] = []
    
    var numberOfItems: Int { departmentList.count }
    
    func viewModel(at indexPath: IndexPath) -> SEDepartmentItemViewModel {
        return SEDepartmentItemViewModel(model: departmentList[indexPath.item])
    }
    
    /// 获取所有科室列表
    func getListOfAllDepartments() {
        SEHttpManager.shared.requestForModelArray(SEDepartmentAPI.listOfAllDepartments, model: SEDepartmentItem.self) { (models, httpStatus) in
            switch httpStatus {
            case .success:
                self.departmentList = models ?? []
            case .auth(let message):
                SEHUD.showError(message: message)
            case .failure(let message):
                SEHUD.showError(message: message)
            }
            self.updateData?(httpStatus)
        }
    }
}

class SEDepartmentItemViewModel: NSObject {
    var model: SEDepartmentItem
    
    init(model: SEDepartmentItem) {
        self.model = model
    }
    
    var itemSize: CGSize {
        CGSize(width: (UIScreen.screenWidth - 15 * 2 - 8 * 2 - 1) / 3, height: 60)
    }
}
